// const SM4 = require('gm-crypt').sm4
import Sm4js from "sm4js";
const key = "iqQlmTQVbbozDKL3"; // 16字节的密钥
const iv = "UZPjvDq4mTQBhvh2"; // 16字节的密钥
// 加密
export const encryptData = (obj: any) => {
  const _config = {
    key: key,
    mode: "cbc", // 加密的方式有两种，ecb和cbc两种
    iv: iv,
    cipherType: "base64",
  };
  const sm4 = new Sm4js(_config);

  return sm4.encrypt(JSON.stringify(obj));
};
// 解密
export const decryptData = (obj: string) => {
  const _config = {
    key: key,
    mode: "cbc", // 加密的方式有两种，ecb和cbc两种
    iv: iv,
    cipherType: "base64",
  };
  const sm4 = new Sm4js(_config);
  return JSON.parse(sm4.decrypt(obj));
};
